<?php

namespace app\model;

use think\Model;

class TrademarkdynamicModel extends Model
{

    protected $connection = 'mysql';

    protected $pk = 'id';

    protected $name = 'trademarkdynamic';
    protected $append = ['images_text','create_time_text','review_num'];

    public function getImagesTextAttr($value,$data)
    {
        if(isset($data['images'])){
            $value  = explode(',', $data['images']);
        }
        return $value;
    }
    public function getCreateTimeTextAttr($value,$data)
    {
        if(isset($data['create_time'])){
            $value  = date('Y-m-d H:i:s',$data['create_time']);
        }
        return $value;
    }

    /**
     * @menu:评论数
     * @Author:男人的坏
     * @Date:2024-03-30 08:55
     */
    public function getReviewNumAttr($value,$data)
    {
        $value = 0;
        if(isset($data['id'])){
            $value  = TrademarkdynamicReviewModel::where(['dynamic_id'=>$data['id']])->count();
        }
        return $value;
    }
}
